<?php
 if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Muser extends MY_Model
{
    public function __construct()
    {
        parent::__construct();
        
    }
    
    public function loginAdmin()
    {
        $uname = $this->getParamString('username');
        $upass = $this->getParamString('password');
        $pass_encode = md5(md5($uname).md5($upass));
        
        $sql = $this->db->query("SELECT id,username,fullname,mobile,level FROM user WHERE username = '".$uname."' AND pword = '".$pass_encode."' ");
        if($sql->num_rows() > 0)
        {
            $data           = $sql->row();
            $data = array(
                'admin_id' => $data->id,
                'username' => $data->username,
                'fullname' => $data->fullname,
		'level' => $data->level
            );
            $this->session->set_userdata($data);
            return '200';
        }
        return '202';
    }
	
	public function getUserProfile($id){
		return $this->db->query('SELECT * FROM user WHERE id = '.$id.' ')->row_object();
	}
	
	public function saveUserProfile($username,$password,$fullname,$email,$mobile,$id){
		$data = array( 
				'fullname' => $fullname,
				'email' => strtolower($email),
				'mobile' => $mobile
				);
		if( !in_array($password,array('',null)) ){
			$data['pword'] = md5(md5($username).md5($password));
		}
		//echo '<pre>';die(print_r($data));
		$this->db->update('user',$data,'id = '.$id.' ');
		return 200;
	}
	
}